package com.zdkj.subway.rca.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zdkj.common.core.util.R;
import com.zdkj.common.log.annotation.SysLog;
import com.zdkj.subway.rca.entity.SwCkDataauditAccinvest;
import com.zdkj.subway.rca.service.SwCkClearRulesService;
import com.zdkj.subway.rca.service.SwCkDataauditAccinvestService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;


/**
 * @Author lu
 * @Date 2021-09-08
 * 清分及划账-数据关联性审核-ACC充值与平台差异对比
 */
@RestController
@AllArgsConstructor
@RequestMapping("/swckdataauditaccinvest" )
@Api(value = "swckdataauditaccinvest", tags = "清分及划账-数据关联性审核-ACC充值与平台差异对比")
public class SwCkDataauditAccinvestController {

	@Autowired
    private final SwCkDataauditAccinvestService swCkDataauditAccinvestService;
    @Autowired
    private final SwCkClearRulesService swCkClearRulesService;

    /**
     * 运营商下拉列表
     * @return
     */
    @ApiOperation(value = "运营商下拉列表", notes = "运营商下拉列表")
    @GetMapping("/listoperators" )
    public R listoperators() {
        return R.ok(swCkClearRulesService.getServiceMap());
    }
    /**
     * 分页查询
     * @param
     * @return
     */
    @ApiOperation(value = "分页查询,startDate 格式：yyyy-MM-dd, endDate 格式： yyyy-MM-dd", notes = "分页查询")
    @GetMapping("/list" )
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "startDate", value = "开始日期：yyyy-MM-dd", dataTypeClass = String.class,required = true),
                    @ApiImplicitParam(name = "endDate", value = "结束日期：yyyy-MM-dd", dataTypeClass = String.class,required = true),
                    @ApiImplicitParam(name = "lineCode", value = "线路编码", dataTypeClass = String.class),
                    @ApiImplicitParam(name = "stationCode", value = "站点编码", dataTypeClass = String.class),
                    @ApiImplicitParam(name = "startReplyDate", value = "回复开始日期：yyyy-MM-dd", dataTypeClass = String.class),
                    @ApiImplicitParam(name = "endReplyDate", value = "回复结束日期：yyyy-MM-dd", dataTypeClass = String.class),
            }
    )
    public R getSwAuMarketingTicketList(Page page, String startDate, String endDate, String lineCode, String stationCode, String startReplyDate, String endReplyDate) {
        if(StringUtils.isEmpty(startDate) ||  StringUtils.isEmpty(endDate)){
            return R.failed("开始日期和结束日期不能为空");
        }
        LambdaQueryWrapper<SwCkDataauditAccinvest> queryWrapper = Wrappers.<SwCkDataauditAccinvest>lambdaQuery()
                .between(StringUtils.isNotEmpty(startDate) && StringUtils.isNotEmpty(endDate), SwCkDataauditAccinvest::getTradeDate, startDate, endDate)
                .between(StringUtils.isNotEmpty(startReplyDate) && StringUtils.isNotEmpty(endReplyDate), SwCkDataauditAccinvest::getReplyDate, startReplyDate, endReplyDate)
                .eq(StringUtils.isNotEmpty(lineCode), SwCkDataauditAccinvest::getLineCode, lineCode)
                .eq(StringUtils.isNotEmpty(stationCode), SwCkDataauditAccinvest::getStationCode, stationCode)
                .orderByDesc(SwCkDataauditAccinvest::getTradeDate)
                .orderByAsc(SwCkDataauditAccinvest::getLineCode,SwCkDataauditAccinvest::getStationCode);
        return R.ok(swCkDataauditAccinvestService.page(page, queryWrapper));
    }

    /**
     * 清分及划账-数据关联性审核-ACC充值与平台差异对比-生成差异报表
     * @return R
     */
    @ApiOperation(value = "清分及划账-数据关联性审核-ACC充值与平台差异对比-生成差异报表，点击“生成差异报表”按钮弹出窗口选择时间段(二者必须选)", notes = "清分及划账-数据关联性审核-ACC充值与平台差异对比-生成差异报表，点击“生成差异报表”按钮弹出窗口选择时间段(二者必须选)")
    @SysLog("清分及划账-数据关联性审核-ACC充值与平台差异对比-生成差异报表" )
    @GetMapping({"/generateDifferenceReport"})
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "startDate", value = "开始日期", dataTypeClass = String.class, required = true),
                    @ApiImplicitParam(name = "endDate", value = "结束日期", dataTypeClass = String.class, required = true)
            }
    )
    public R generateDifferenceReport(String startDate, String endDate) {
        try {
            if (StringUtils.isEmpty(startDate) || StringUtils.isEmpty(endDate)){
                return R.failed();
            }
            swCkDataauditAccinvestService.generateDifferenceReport(startDate, endDate);

            return R.ok();
        } catch (Exception e) {
            e.printStackTrace();
            return R.failed();
        }

    }

    
    /**
     * ACC充值与平台差异对比导入
     * @param file
     * @return
     * @throws Exception
     */
    @ApiOperation(value = "ACC充值与平台差异对比导入", notes = "ACC充值与平台差异对比导入")
    @SysLog("ACC充值与平台差异对比导入")
    @PostMapping({ "/importAccInvest" })
    public R importAccInvest(@RequestParam("file") final MultipartFile file) throws Exception {
        R validation = swCkDataauditAccinvestService.importAccInvest(file);
        if(1 == validation.getCode()){
            return validation;
        }
        return R.ok();
    }
    /**
     * 导出
     * @param
     * @return
     */
    @ApiOperation(value = "导出", notes = "导出")
    @GetMapping({"/export"})
    @SysLog("ACC充值与平台差异对比-导出")
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "startDate", value = "开始日期：yyyy-MM-dd", dataTypeClass = String.class,required = true),
                    @ApiImplicitParam(name = "endDate", value = "结束日期：yyyy-MM-dd", dataTypeClass = String.class,required = true),
                    @ApiImplicitParam(name = "lineCode", value = "线路编码", dataTypeClass = String.class),
                    @ApiImplicitParam(name = "stationCode", value = "站点编码", dataTypeClass = String.class),
                    @ApiImplicitParam(name = "startReplyDate", value = "回复开始日期：yyyy-MM-dd", dataTypeClass = String.class),
                    @ApiImplicitParam(name = "endReplyDate", value = "回复结束日期：yyyy-MM-dd", dataTypeClass = String.class),
            }
    )
    public void export(String startDate,String endDate, String lineCode, String stationCode,String startReplyDate, String endReplyDate, HttpServletResponse response) {
        if(StringUtils.isEmpty(startDate) ||  StringUtils.isEmpty(endDate)){
            return;
        }
        swCkDataauditAccinvestService.export(startDate,endDate,lineCode,stationCode,startReplyDate,endReplyDate,response);
    }


}
